package com.example.teaching_server.repository;

import com.example.teaching_server.entity.StudentStatisticsEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * 学生统计数据访问层
 */
@Repository
public interface StudentStatisticsRepository extends JpaRepository<StudentStatisticsEntity, Long> {

    /**
     * 根据学生ID和学期ID查找统计信息
     */
    Optional<StudentStatisticsEntity> findByStudentIdAndTermId(Long studentId, Long termId);

    /**
     * 根据学生ID列表和学期ID查找统计信息
     */
    @Query("SELECT ss FROM StudentStatisticsEntity ss WHERE ss.studentId IN :studentIds AND ss.termId = :termId")
    List<StudentStatisticsEntity> findByStudentIdsAndTermId(@Param("studentIds") List<Long> studentIds,
                                                            @Param("termId") Long termId);
}
